   <!DOCTYPE html>
<html>
<head>
<head />
<div th:include="base-libs :: base-libs" />
<title>服务管理</title>
<style type="text/css">
.topBtn{
	float: right;
	margin-right:10px;
	margin-top:5px
}
.laydate-icon{
	border:1px solid #B6B6B6
}
</style>
</head>
<script th:inline="javascript">
	/**医联体信息*/
	var qysqxx = [[${qysqxx}]];
	/**服务信息*/
	var fwxx = [[${fwxx}]];
	/**提供机构信息*/
	var tgfwjgxx = [[${tgfwjgxx}]];
	/**服务管理信息*/
	var fwglxx = [[${fwglxx}]];
	/**接收机构列表*/
	var jsjglb = [[${jsjglb}]];
</script>
<script type="text/javascript">
	$(function() {
		$(this).registerManagerPage();
		initView();
		initData(); 
	});

	function initData() {
		/**加载医联体信息*/
		initQysqxx();
		$("#managerForm").attr("action", "save");
		/**加载提供服务机构信息*/
		if(tgfwjgxx){
			$("#TGFWJGID").val(tgfwjgxx["YLJGID"]);
			$("#TGFWJGMC").val(tgfwjgxx["YLJGMC"]);
		}
		
		/**服务管理信息*/
		if(fwglxx){
			$("#method").val("update");
			$(".fwgl").each(function(){
				$(this).val(fwglxx[$(this).attr("id")]);
			});
			$("#BLID").val(fwglxx["BLID"]);
			$("#BLXZ").val(fwglxx["HZXM"]+"\t"+fwglxx["ZDMC"]);
			$("#JSFWJG").combobox("setValues", fwglxx["JSFWJG"].split(","));
			$("#FWID").val(fwglxx["FWID"]);
			$("#FWID").trigger("change");
		}
		 
	}

	function initView() {
		$("#BLTR").hide();
		$("#JSFWJG").combobox({    
		    valueField: "PTJGID",    
		    textField: "YLJGMC",  
		    width:"220px",
		    height:"30px",
		    multiple: true,
		    panelHeight:'auto'
		}); 
		
		/**创建服务项下拉框*/
		initFwxxInput();
		
		/**创建接收服务下拉*/
		if(jsjglb){
			$(jsjglb).each(function(index, item){
				if(item["PTJGID"]== tgfwjgxx["YLJGID"]){
					jsjglb.splice(index, 1);
				}
			});
			$("#JSFWJG").combobox("loadData", jsjglb);
		}
		
		$("#_easyui_textbox_input2").attr("readonly","readonly");
		
		$("#FWID").on("change", function(){
			var info = $("#FWID option:selected").data("FWXX");
			if(info["XZBL"] == "1"){
				$("#BLTR").show();
				$("#BLXZ").addClass("form-control");
				$("#FWNR").val(info["FWNR"]);
			}else{
				$("#BLTR").hide();
				$("#BLID").val("");
				$("#BLXZ").val("");
				$("#BLXZ").removeClass("form-control");
				$("#FWNR").val(info["FWNR"]);
			}
		});
		
		/**选择医联体*/
		$("#xzYlt").on("click", function(){
			//页面层
			var cache = {};
			cache["YLTID"] = $("#YLTID").val();
			cache["YLJGID"] = $("#TGFWJGID").val();
			StoreCache.setCache("FWGL_YLTXX", cache);
			parent.layer.open({
				type: 2,
		  		area: ["80%", "500px"], //宽高
		  		scrollbar: false,
		  		resize: false,
				move: false,
				title:"医联体信息列表",
				content: contextRoot + "fwgl/" +"ylt.html",
				end: function () {
					var info = StoreCache.removeCache("FWGL_YLTXX");
					if(info){
						/**重新加载数据*/
						qysqxx = info["qysqxx"];
						initQysqxx();
						jsjglb = info["jsjglb"];
						$(jsjglb).each(function(index, item){
							if(item["PTJGID"]== tgfwjgxx["YLJGID"]){
								jsjglb.splice(index, 1);
							}
						});
						$("#JSFWJG").combobox("loadData", jsjglb);
						
						//协议服务信息
						fwxx = info["xyfwxx"];
						initFwxxInput();
					} 
				}
			});
		});
		
		/**选择病例*/
		$("#xzBl").on("click", function(){
			//页面层
			var cache = {};
			cache["YLJGID"] = $("#TGFWJGID").val();
			cache["BLID"] = $("#BLID").val();
			StoreCache.setCache("FWGL_BLXX", cache);
			parent.layer.open({
				type: 2,
		  		area: ["80%", "500px"], //宽高
		  		scrollbar: false,
		  		resize: false,
				move: false,
				content: contextRoot + "fwgl/" +"bl.html",
				end: function () {
					var info = StoreCache.removeCache("FWGL_BLXX");
					if(info){
						$("#BLID").val(info["BLID"]);
						$("#BLXZ").val(info["HZXM"]+"\t"+info["ZDMC"])
					} 
				}
			});
		});
		
		/**提交按钮*/
		$("#btnSave").on("click", function(){
			if($(".form-control").QuickValidate() && validateJg()){
				var params = {};
				params["method"] = $("#method").val();
				params["YLJGIDS"] = $("#JSFWJG").combobox("getValues");
				params["YQFWSJ"] = $("#YQFWSJ").val();
				params["BLID"] = $("#BLID").val();
				$.QuickRemote.AjaxFiledFormSubmit("managerForm", function(result) { 
					var info = result["info"];
					if (result["state"]) {
						$.QuickAlert.alertNormal("新建服务成功！",{callback: function(){
							$.QuickUrlUtils.redirectUrl("index.html");
						}});
					} else {
						$.QuickAlert.alertFail({
							content : info["faultInfo"]
						});
					}
				}, params);
			}
		});
	}

	
	
	/**返回按钮*/
	function btnBackHandler() {
		$.QuickUrlUtils.redirectUrl("index.html");
	}
	
	/**加载医联体信息*/
	function initQysqxx(){
		if(qysqxx){
			$(".yltxx").each(function(){
				$(this).val(qysqxx[$(this).attr("id")]);
			});
		}
	}
	
	/**校验接收机构*/
	function validateJg(){
		var flag = true;
		var val = $("#JSFWJG").combobox("getValues");
		
		if(StringUtils.isEmpty(val)){
			flag = false;
			$.QuickAlert.alertFail({
				content : "请选择接收服务机构！"
			});
		}
		return flag;
	}
	
	/**创建服务项下拉框*/
	function initFwxxInput(){
		$("#FWID").empty();
		var opts = [];
		opts.push($("<option>").text("请选择").val("").data("FWXX",{XZBL:"0",FWNR:""}));
		$(fwxx).each(function(index, item){
			var opt = $("<option>").text(item["FWMC"]).val(item["FWID"]).data("FWXX",item);
			opts.push(opt);
		});
		$("#FWID").append(opts);
	}
</script>

<body style="overflow-y: scroll">
<div id="maxDiv" style="height: 670px;">
	<div id="maxLayout" class="easyui-layout" fit="true">
		<div region="center" style="border: none; overflow: hidden;">
			<h4 class="h4-title" style="font-size: 18px;text-align:center;">
				新建服务
			</h4>
			<div class="form-table-box" >
				<input id="method" style="display: none;" value="add">
				<form id="managerForm" class="form-horizontal" >
					<h4 class="h4-title" style="font-size: 13px;">
						医联体信息
					</h4>
					<table class="form-table">
						<tr>
							<td class="td-text">
								<span class="quick-not-null">*</span>
								<label>医联体名称：</label>
							</td>
							<td class="td-content">
								<input id="YLTID" name="YLTID" class="yltxx" style="display: none;"/>
								<input id="YLTMC" class="form-control yltxx" type="text" style="width: 55%;"
									quick-config="label:'医联体名称', validateProxy:'notNull'"
									readonly="readonly" placeholder="医联体名称">
								<!-- 按钮触发模态框 -->
								<button class="btn" type="button"  style="width: 36%;"  id="xzYlt">选择</button>
						
							</td>
							<td class="td-text">
								<label>医联体类型：</label>
							</td>
							<td class="td-content">
								<input id="YLTLXMC" readonly="readonly"  name="YLTLX" class="yltxx" style="width:90%;">
							</td>
							<td class="td-text">
								<label>主导医疗机构：</label>
							</td>
							<td class="td-content">
								<input id="ZDYLJGMC" readonly="readonly" class="yltxx">
							</td>
						</tr>
						<tr>
							<td class="td-text">
								<label>签约有效期：</label>
							</td>
							<td class="td-content">
								<input id="QYYXQMC" class="yltxx" readonly="readonly">
							</td>
							<td class="td-text">
								<label>签约时间：</label>
							</td>
							<td class="td-content">
								<input id="QYSJ" readonly="readonly" class="yltxx" />
							</td>
							<td class="td-text">
								<label>至</label>
							</td>
							<td class="td-content">
								<input id="DQSJ" readonly="readonly"class="yltxx" /><!-- onclick="laydate(end)" -->
							</td> 
						</tr>
					</table>
					<h4 class="h4-title" style="font-size: 13px;">
						服务信息
					</h4>
					<table class="form-table ">
						<tr>
							<td class="td-text">
								<label>提供服务机构：</label>
							</td>
							<td class="td-content">
								<input id="FWGLID" name="FWGLID" class="fwgl" style="display: none;" type="text">
								<input id="TGFWJGID" name="TGFWJGID" style="display: none;" type="text">
								<input id="TGFWJGMC" name="TGFWJGMC" class="form-control" type="text">
							</td>
							<td class="td-text">
								<span class="quick-not-null">*</span>
								<label>接收服务机构：</label>
							</td>
							<td class="td-content">
								<input id="JSFWJG" class="easyui-combobox">
							</td>
							<td class="td-text">
								<label>预期服务时间：</label>
							</td>
							<td class="td-content">
								<input id="YQFWSJ"  style="width:83%;height:30px;"
							class="form-control input-text laydate-icon fwgl" onclick="laydate()"  readonly="readonly"
							quick-config="label:'预期服务时间', validateProxy:'notNull'"/>
							</td>
						</tr>
						<tr>
							<td class="td-text">
								<label>服务项：</label>
							</td>
							<td class="td-content" colspan="5">
								<select id="FWID" name="FWID" class="form-control" style="width:98%;"
								 quick-config="label:'服务项', validateProxy:'notNull'"></select>
							</td>
						</tr>
						<tr>
							<td class="td-text">
								<label>服务内容：</label>
							</td>
							<td class="td-content" colspan="5">
								<input id="FWNR" class="form-control fwgl" type="text" style="width:98%;"
									readonly="readonly">
							</td>
						</tr>
						<tr id="BLTR">
							<td class="td-text">
								<span class="quick-not-null">*</span>
								<label>病例选择：</label>
							</td>
							<td class="td-content" colspan="5">
								<input id="BLID" style="display: none;"/>
								<input id="BLXZ" class="" type="text" style="width: 85.5%;"
								quick-config="label:'病例选择', validateProxy:'notNull'" readonly="readonly">
								<button class="btn" type="button"  style="width: 12%;"  id="xzBl">选择</button>
							</td>
						</tr>
						<tr>
							<td class="td-text">
								<label>备注：</label>
							</td>
							<td class="td-content" colspan="5">
								<input id="BZ" name="BZ" class="form-control fwgl" style="width:98%;" type="text"
								quick-config="label:'备注', validateProxy:'length', length: '200'" >
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div style="text-align:center;margin-top:10px">
				<button class="btn"  type="button" id="btnSave">提交</button>
				<button class="btn" type="button" onclick="btnBackHandler()">返回</button>
			</div>
		</div>
	</div>
</div>
</body>
</html>


